package cn.sumpu.app.wlcity.web.mvc.light;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.sumpu.app.wlcity.biz.ContentBiz;
import cn.sumpu.app.wlcity.domain.Content;
import cn.sumpu.app.wlcity.exception.AppBusinessException;
import cn.sumpu.app.wlcity.util.Common;

@Controller
public class LightController {
	@Autowired
	private ContentBiz contentBiz;

	@RequestMapping(value = "/light.htm")
	public String light() {
		return "light/index";
	}

	//精彩看点
	@RequestMapping(value = "/lightHot.htm")
	public String hot(Integer page, HttpServletRequest request) {
		if (page == null) {
			page = 1;
		}
		try {
			String radioApp =Common.APP_LIGHT;
			List<Content> hotList = contentBiz.getContentHotList(page,Common.TYPE_HOT,radioApp);
			int size = contentBiz.getContentListCount(Common.TYPE_HOT,radioApp);
			int totalPage = (size + Common.PAGE_SIZE_HOT - 1)/ Common.PAGE_SIZE_HOT;
			request.setAttribute("totalPage", totalPage);
			request.setAttribute("hotList", hotList);
			request.setAttribute("link", "hot.htm");
			request.setAttribute("currentPage", page);
		} catch (AppBusinessException e) {
			e.printStackTrace();
			return "hotspring/error";
		}
		return "light/hot/hot";
	}
	
	@RequestMapping(value = "/lightHotDetail.htm")
	public String hotDetail(String id,HttpServletRequest request) {
		
		try {
			Content content = contentBiz.getContentById(id);
			request.setAttribute("content", content);
		} catch (AppBusinessException e) {
			e.printStackTrace();
			return "hotspring/error";
		}
		return "light/hot/hotDetail";
	}
	
	//灯会扫描
	@RequestMapping(value = "/lightIntro.htm")
	public String lightIntroduction(Integer page,HttpServletRequest request) {
		if(page == null){
			page = 1;
		}
		try {
			String radioApp =Common.APP_LIGHT;
			List<Content> lightScanList = contentBiz.getContentHotList(page,Common.LIGHT_SCAN,radioApp); 
			int size = contentBiz.getContentListCount(Common.LIGHT_SCAN,radioApp);
			int totalPage = (size + Common.PAGE_SIZE_INTRODUCTION - 1) / Common.PAGE_SIZE_INTRODUCTION;
			request.setAttribute("totalPage", totalPage);
			request.setAttribute("lightScanList", lightScanList);
			request.setAttribute("link", "introduction.htm");
			request.setAttribute("currentPage", page);
		} catch (AppBusinessException e) {
			e.printStackTrace();
			return "hotspring/error";
		}
		return "light/introduction/introduction";
	}
	
	@RequestMapping(value = "/lightIntroDetail.htm")
	public String lightIntroDetail(String id,HttpServletRequest request) {
		
		try {
			Content content = contentBiz.getContentById(id);
			request.setAttribute("content", content);
		} catch (AppBusinessException e) {
			e.printStackTrace();
			return "hotspring/error";
		}
		return "light/introduction/introDetail";
	}
	//投票
	@RequestMapping(value = "/lightTicket.htm")
	public String lightTicket() {
		return "light/ticket";
	}
	//服务指南
	@RequestMapping(value = "/lightGuide.htm")
	public String lightGuide(Integer page,HttpServletRequest request) {
		if(page == null){
			page = 1;
		}
		try {
			String radioApp =Common.APP_LIGHT;
			List<Content> lightGuideList = contentBiz.getContentHotList(page,Common.LIGHT_GUIDE,radioApp); 
			int size = contentBiz.getContentListCount(Common.LIGHT_SCAN,radioApp);
			int totalPage = (size + Common.PAGE_SIZE_INTRODUCTION - 1) / Common.PAGE_SIZE_INTRODUCTION;
			request.setAttribute("totalPage", totalPage);
			request.setAttribute("lightGuideList", lightGuideList);
			request.setAttribute("link", "lightService.htm");
			request.setAttribute("currentPage", page);
		} catch (AppBusinessException e) {
			e.printStackTrace();
			return "hotspring/error";
		}
		return "light/guide/guide";
	}
	@RequestMapping(value = "/lightGuideDetail.htm")
	public String lightGuideDetail(String id,HttpServletRequest request) {
		
		try {
			Content content = contentBiz.getContentById(id);
			request.setAttribute("content", content);
		} catch (AppBusinessException e) {
			e.printStackTrace();
			return "hotspring/error";
		}
		return "light/guide/guideDetail";
	}
	//灯会合作商家
	@RequestMapping(value = "/lightBusiness.htm")
	public String lightBusiness(Integer page,HttpServletRequest request) {
		if(page == null){
			page = 1;
		}
		try {
			String radioApp =Common.APP_LIGHT; 
			List<Content> contentList = contentBiz.getContentList(page,Common.TYPE_COMPANY,radioApp);
			int size = contentBiz.getContentListCount(Common.LIGHT_SCAN,radioApp);
			int totalPage = (size + Common.PAGE_SIZE_INTRODUCTION - 1) / Common.PAGE_SIZE_INTRODUCTION;
			request.setAttribute("totalPage", totalPage);
			request.setAttribute("contentList", contentList);
			request.setAttribute("link", "introduction.htm");
			request.setAttribute("currentPage", page);
		} catch (AppBusinessException e) {
			e.printStackTrace();
			return "hotspring/error";
		}
		return "light/company/company";
	}
	@RequestMapping(value = "/lightCompanyDetail.htm")
	public String lightCompanyDetail(String id,HttpServletRequest request) {
		
		try {
			Content content = contentBiz.getContentById(id);
			request.setAttribute("content", content);
		} catch (AppBusinessException e) {
			e.printStackTrace();
			return "hotspring/error";
		}
		return "light/company/companyDetail";
	}
}
